home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech's Sprocket™ / SprocketGX / AppSpecific / GXDocWindow.cp < prev    next >
Encoding:
Text File  |  1994-10-18  |  20.4 KB  |  738 lines  |  [TEXT/MMCC]

  1. /*
  2.     File:        GXWindow.cp
  3.  
  4.     Contains:    The prototype GX window
  5.                 
  6.     Written by: Jon Summers
  7.     
  8.     Copyright:    © 1994 by Jon Summers, all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.     
  12.  */
  13.  
  14. #include "GXDocWindow.h"
  15. #include "GXDocFile.h"
  16. #include "GXToolWindow.h"
  17. #include "AppLib.h"
  18.  
  19. TGXDocWindow::TGXDocWindow()
  20.  :
  21. #if    qUseQuickDrawGX
  22.     fDocJob( nil),
  23.     fPage(nil),
  24. #endif    // qUseQuickDrawGX
  25.      fPagesInDoc(0),
  26.     fDocPageNum(0)
  27. {
  28.     short    aCount = kMaxPageFormats;
  29.     
  30.     while (aCount--)
  31.         fPageFormats[aCount] = nil;
  32.     
  33.  
  34. #if    qUseQuickDrawGX
  35.  
  36.     if (fWindow)
  37.     {
  38.         gxViewPort     aWindowViewPort;
  39.         gxViewPort     aContentViewPort;
  40.         gxMapping     aContentMapping;
  41.         gxShape        aContentViewPortShape;
  42.         gxShapeAttribute    aContentViewPortShapeAttribute;
  43.         Rect    aPortRect = fWindow->portRect;
  44.         gxRectangle    aViewRect;
  45.         
  46.         // Inset the shape...
  47.         aViewRect.top = ff(aPortRect.top + kHeaderHeight);
  48.         aViewRect.bottom = ff(aPortRect.bottom - kScrollbarWidth);
  49.         aViewRect.right = ff(aPortRect.right - kScrollbarWidth);
  50.         aViewRect.left = ff(aPortRect.left);
  51.  
  52.             GXIgnoreGraphicsNotice(transform_already_set);    // <<••
  53.         aWindowViewPort = GXNewWindowViewPort(fWindow);
  54.  
  55.         GXValidateViewPort(aWindowViewPort);
  56.         // Create a child port for scrolling the page shape: IM-QD GX Objects pp 7-45, 7-46
  57.         aContentViewPort = GXNewViewPort(GXGetViewPortViewGroup(aWindowViewPort));
  58.         fContentViewPort = aContentViewPort;
  59.         (void)GXGetViewPortMapping(aContentViewPort, &aContentMapping);
  60.         (void)MoveMappingTo(&aContentMapping, kHeaderHeight, 0);
  61.         GXSetViewPortMapping(aContentViewPort, &aContentMapping);
  62.         GXSetViewPortParent(aContentViewPort, aWindowViewPort);
  63.         SetDefaultViewPort(aContentViewPort);
  64.             GXPopGraphicsNotice();            // <<••
  65.         this->ResetContentClip();
  66.         
  67.     // Create the page shape. We set the unique items attribute to make sure that each item
  68.     // added to the picture has a unique reference. If this attribute was not set, we would
  69.     // not see all copies of anything we add to the shape multiple times -- we'd just see
  70.     // the last version added.    
  71.             
  72.         aContentViewPortShape = GXNewShape(gxPictureType);
  73.         GXValidateShape(aContentViewPortShape);
  74.         aContentViewPortShapeAttribute = GXGetShapeAttributes(aContentViewPortShape);
  75.         aContentViewPortShapeAttribute |= gxUniqueItemsShape;
  76.         GXSetShapeAttributes(aContentViewPortShape, aContentViewPortShapeAttribute);
  77.         GXValidateShape(aContentViewPortShape);
  78.         fPage = aContentViewPortShape;
  79.     }
  80.     else
  81.         SysBeep(10);
  82. // Create a print job for this document.  This will be the same as the system default until
  83. // the user goes through the dialogs for Page Setup or Print…
  84.     if (GXNewJob(&fDocJob) == noErr)
  85.     {
  86. // Now install our application override for PrintingEvent so that we can
  87. // support the new movable-modal printing dialog boxes.
  88.         GXInstallApplicationOverride(fDocJob, gxPrintingEvent, gAppPrintingOverrideUPP);
  89.     }
  90.     else
  91.         fDocJob = nil;
  92.     
  93.     fDocPageNum = fPagesInDoc = 1;
  94.     SetInspectPage(fDocPageNum, fPagesInDoc);
  95.     SetInspectShape(ePageShape, fPage);
  96. #endif    // qUseQuickDrawGX
  97. }
  98.  
  99. TGXDocWindow::~TGXDocWindow()
  100. {
  101. #if    qUseQuickDrawGX
  102.     short    aCount = kMaxPageFormats;
  103.     if (GetDocShape())
  104.         GXDisposeShape(GetDocShape());     // Dispose of this doc's shape.
  105.     if (GetDocJob())
  106.         GXDisposeJob(GetDocJob());        // Dispose of this doc's print job.
  107.     while (aCount--)
  108.         if (fPageFormats[aCount])
  109.             GXDisposeFormat(fPageFormats[aCount]);
  110.         
  111.     SetInspectPage(0, 0);
  112.     SetInspectShape(ePageShape, nil);
  113. #endif    // qUseQuickDrawGX
  114. }
  115.  
  116. void    TGXDocWindow::Select(void)
  117. {
  118.     TDocWindow::Select();
  119. #if    qUseQuickDrawGX
  120.     SetInspectPage(fDocPageNum, fPagesInDoc);
  121.     SetInspectShape(ePageShape, fPage);
  122. #endif    // qUseQuickDrawGX
  123. }
  124.  
  125. void TGXDocWindow::Activate(Boolean theIsActivating)
  126. {
  127.     TDocWindow::Activate(theIsActivating);
  128. #if    qUseQuickDrawGX
  129.     if (theIsActivating)
  130.     {
  131.         SetInspectPage(fDocPageNum, fPagesInDoc);
  132.         SetInspectShape(ePageShape, fPage);
  133.     }
  134. #endif    // qUseQuickDrawGX
  135. }
  136.  
  137. void TGXDocWindow::Click(EventRecord* /*pEvent*/)
  138. {
  139.     if (fWindow != FrontNonFloatingWindow())
  140.         this->Select();
  141. }
  142.  
  143. void TGXDocWindow::SetupMenus(void)
  144. {
  145.     TDocWindow::SetupMenus();
  146.     if (fPagesInDoc)
  147.     {
  148.         if (fDocPageNum < fPagesInDoc)
  149.             EnableMenuItem(mEdit, iNextPage, true);
  150.         if (fDocPageNum > 1)
  151.             EnableMenuItem(mEdit, iPreviousPage, true);
  152.         if (fPagesInDoc > 1)
  153.             EnableMenuItem(mEdit, iGotoPage, true);
  154.     }
  155. }
  156.  
  157. void TGXDocWindow::AdjustCursor(EventRecord* pEvent)
  158. {
  159.     Point        aLocalMouse = pEvent->where;
  160.     Rect        aContentRect;
  161.     
  162.     GetContentRect(&aContentRect);
  163.     {
  164.         CSavePort  aSavePort(fWindow);
  165.  
  166.         GlobalToLocal(&aLocalMouse);
  167.     }
  168. #if    qUseQuickDrawGX
  169.     if (fPage && (fWindow == FrontNonFloatingWindow()))
  170.     {
  171.         if (PtInRect(aLocalMouse, &aContentRect))
  172.         {
  173.             Boolean        aOptKey = ((pEvent->modifiers & optionKey) == optionKey);
  174.             gxPoint        aGXMouse;
  175.             gxShapeAttribute    aShapeAttribute;
  176.             gxHitTestInfo    aHitTestInfo;
  177.             gxShape    aTestPart = nil;
  178.             // optionkey:  squirrel down to LOWEST level
  179.             short        aLevel = (aOptKey ? 0 : 1);
  180.             short        aDepth = (aOptKey ? 0 : 1);
  181.             
  182.             aGXMouse.x = ff(aLocalMouse.h);
  183.             aGXMouse.y = ff(aLocalMouse.v);
  184.     
  185.              GXIgnoreGraphicsNotice (attributes_already_set);        // <<••
  186.              GXIgnoreGraphicsNotice (transform_already_set);        // <<••
  187.              GXIgnoreGraphicsNotice (parameter_out_of_range);    // <<••
  188.             aShapeAttribute = GXGetShapeAttributes(fPage);
  189.             GXSetShapeHitTest(fPage, gxGeometryPart, ff(0));
  190.             // Getting grpahics ERROR: parameter_out_of_range
  191.             // IM QD GX: Graphics pp 6-49,69
  192.             aTestPart = GXHitTestPicture(fPage, &aGXMouse, &aHitTestInfo, aLevel, aDepth);
  193.             GXSetShapeAttributes(fPage, aShapeAttribute);
  194.              GXPopGraphicsNotice();        // <<••    parameter_out_of_range
  195.              GXPopGraphicsNotice();        // <<••    transform_already_set
  196.              GXPopGraphicsNotice();        // <<••    attributes_already_set
  197.             
  198.             if (aTestPart == nil)
  199.                 InitCursor();
  200.             else
  201.                 SetCursor(*GetCursor(aOptKey ? 3 : 2));
  202.  
  203.             SetInspectShape(eTestShape, aTestPart);
  204.             return;
  205.         }
  206.         SetInspectShape(eTestShape, nil);
  207.     }
  208. #endif    // qUseQuickDrawGX
  209.     InitCursor();
  210. }
  211.  
  212. #if        READJOB
  213.  
  214. OSErr TGXDocWindow::SavePrintInfo(MyDocumentPtr whichDocument, short resRefNum)
  215. {
  216.     OSErr        err;
  217.     Handle        thePrintData, oldPrintData;
  218.     OSType        dataResType;
  219.     short        dataResID;
  220.  
  221. /*
  222.     If QuickDraw GX is present, flatten the document's gxJob into a
  223.     handle so that we can write it to disk.  Otherwise, make a copy
  224.     of the document's print handle.  In either case, set up the
  225.     resource type and ID to use.  Notice how smoothly this makes
  226.     the rest of the routine work.  We don't need to worry about
  227.     whether we're storing a gxJob or a print record to disk.
  228. */
  229.  
  230.     UseResFile(resRefNum);
  231.  
  232.     if (gGXIsPresent)
  233.     {
  234.         err = MySaveFormatRefs(whichDocument);
  235.         nrequire(err, CouldNotSaveFormatRefs);
  236.  
  237.         thePrintData = NewHandle(0);
  238.         GXFlattenJobToHdl(whichDocument->documentJob, thePrintData);
  239.         err = GXGetJobError(whichDocument->documentJob);
  240.         nrequire(err, CouldNotFlattenJob);
  241.  
  242.         dataResType = kMyJobType;
  243.         dataResID = kMyJobID;
  244.     }
  245.     else
  246.     {
  247.         thePrintData = (Handle) whichDocument->documentPrintHdl;
  248.         err = HandToHand(&thePrintData);
  249.         nrequire(err, CouldNotDuplicatePrintHdl);
  250.  
  251.         dataResType = kMyPrintRecType;
  252.         dataResID = kMyPrintRecID;
  253.     }
  254.  
  255. // If there's an existing resource, delete it.
  256.  
  257.     oldPrintData = Get1Resource(dataResType, dataResID);
  258.  
  259.     if (oldPrintData != nil)
  260.     {
  261.         RmveResource(oldPrintData);
  262.         UpdateResFile(resRefNum);
  263.         DisposHandle(oldPrintData);
  264.     }
  265.  
  266. // Add our new resource.
  267.  
  268.     AddResource(thePrintData, dataResType, dataResID, "\p");
  269.     err = ResError();
  270.     nrequire(err, CouldNotAddResource);
  271.  
  272.     WriteResource(thePrintData);
  273.     UpdateResFile(resRefNum);
  274.     DetachResource(thePrintData);
  275.  
  276. CouldNotAddResource:
  277.     DisposHandle(thePrintData);
  278.  
  279. CouldNotDuplicatePrintHdl:
  280. CouldNotFlattenJob:
  281. CouldNotSaveFormatRefs:
  282.     return err;
  283. }
  284.  
  285. /************************************************************
  286.   MyLoadPrintInfo - This routine loads our document's
  287.   previously saved print record or gxJob data.
  288.  
  289. *************************************************************/
  290.  
  291. OSErr TGXDocWindow::LoadPrintInfo(MyDocumentPtr whichDocument, short resRefNum)
  292. {
  293.     OSErr        err = noErr;
  294.     THPrint        savedPrintHdl;
  295.     Handle        theJobData = nil;
  296.     
  297.     UseResFile(resRefNum);
  298.  
  299. /*
  300.     If we're using QuickDraw GX, and there's a job resource saved,
  301.     load it and unflatten it.  Any format references saved with a
  302.     document are no longer valid, so we need to adjust them.
  303. */
  304.     theJobData = Get1Resource(kMyJobType, kMyJobID);
  305.  
  306.     if (theJobData != nil)
  307.     {
  308.         GXUnflattenJobFromHdl(whichDocument->documentJob, theJobData);
  309.         err = GXGetJobError(whichDocument->documentJob);
  310.         ReleaseResource(theJobData);
  311.  
  312.         if (err == noErr)
  313.             err = MyAdjustFormats(whichDocument);
  314.     }
  315.  
  316. /*
  317.     If there was no job data saved or we're not using QuickDraw GX,
  318.     try to load a previously saved print record.  If we find one,
  319.     and QuickDraw GX is being used, convert the print record to
  320.     a gxJob.  Otherwise, if we find one and QuickDraw GX is not
  321.     being used, dispose of the print handle that we allocated in
  322.     our MyCreateDocument routine.
  323.     
  324.     Note that if no gxJob or print record was previously saved,
  325.     we'll simply end up using the one we created in our
  326.     MyCreateDocument routine.  So, no matter what, we'll always
  327.     have a gxJob or print record to use!
  328. */
  329.     if (theJobData == nil)
  330.     {
  331.         savedPrintHdl = (THPrint) Get1Resource(kMyPrintRecType, kMyPrintRecID);
  332.  
  333.         if (savedPrintHdl != nil)
  334.         {
  335.             DetachResource((Handle) savedPrintHdl);
  336.  
  337.             if (gGXIsPresent)
  338.             {
  339.                 GXConvertPrintRecord(whichDocument->documentJob, savedPrintHdl);
  340.                 DisposeHandle((Handle) savedPrintHdl);
  341.                 err = GXGetJobError(whichDocument->documentJob);
  342.             }
  343.             else
  344.             {
  345.                 DisposHandle((Handle) whichDocument->documentPrintHdl);
  346.                 whichDocument->documentPrintHdl = savedPrintHdl;
  347.             }
  348.         }
  349.     }
  350.     
  351.     return err;
  352. }
  353. #endif    //    READJOB
  354.  
  355. #define        kSpoolBufSize        (32*1024)
  356.  
  357. OSErr TGXDocWindow::ReadPage(long  thePageNum)
  358. {
  359.     OSErr    anErr = fnfErr;
  360. #if    qUseQuickDrawGX
  361.     TGXDocFile*        aGxDocFile = (TGXDocFile*)fDocFile;
  362.     if (aGxDocFile)
  363.     {
  364.         gxShape  aPage;
  365.         
  366.         SetCursor(*GetCursor(watchCursor));
  367.         anErr = aGxDocFile->ReadPageShape(thePageNum, &aPage, fContentViewPort);
  368.         if (anErr == noErr)
  369.         {
  370.             {
  371.                 CSavePort  aSavePort(fWindow);
  372.                 Rect        aViewRect;
  373.                 GetContentRect(&aViewRect);
  374.                 InvalRect(&aViewRect);
  375.             }
  376.             
  377.             GXDisposeShape(fPage);
  378.             fPage = aPage;
  379.             fDocPageNum = thePageNum;
  380.             fPagesInDoc = aGxDocFile->DocNumOfPages();
  381.             SetInspectPage(fDocPageNum, fPagesInDoc);
  382.             SetInspectShape(ePageShape, fPage);
  383.         }
  384.         InitCursor();
  385.     }
  386. #endif    // qUseQuickDrawGX
  387.     return anErr;
  388. }
  389.  
  390. /*------ CreateSampleImage -----------------------------------------------------------------*/
  391. //
  392. //    This function creates  primitive shapes and adds them to the window's page shape.
  393. //
  394. void TGXDocWindow::CreateSampleImage(void)
  395. {
  396. #if    qUseQuickDrawGX
  397. //    DebugStr("\pCreateSampleImage");
  398.     if (gQuickDrawGXClient)
  399.     {
  400.         gxShape        aPageShape;
  401.         gxShape         aLineShape;
  402.         gxLine            aLineData = {{ff(25), ff(25)}, {ff(125), ff(125)}};
  403.         gxShape        aRectShape;
  404.         gxRectangle     aRectData = {ff(25), ff(25), ff(75), ff(75)};    
  405.         gxShape         aCurveShape;
  406.         gxCurve         aCurveData = {{ff(25), ff(25)}, {ff(275), ff(75)}, {ff(125), ff(125)}};    
  407.         gxShape         aPathShape;
  408.         long             a888Data[] = {    1 /* # of contours */, 
  409.                                                 6 /* # of points */, 
  410.                                                 0xff000000,
  411.                                                    0, 0,  // the points 
  412.                                                    ff(75),  0, 
  413.                                                    ff(5), ff(50),
  414.                                                    ff(75),  ff(100),
  415.                                                    0,  ff(100), 
  416.                                                    ff(75), ff(50)};        
  417.         gxShape         aTextShape;
  418.         gxRectangle     aTextBounds;
  419.         gxColor         aTextColour;
  420.         Fixed            x,y;
  421.         short            loop;
  422.         gxShape         aPolygonShape;
  423.         long aStarData[] = {    1,                                  // number of contours
  424.                              5 ,                                 // number of points
  425.                             ff(60), 0, ff(90), ff(90),  ff(0), ff(30),
  426.                             ff(120), ff(30), ff(0), ff(90)};     // the points
  427.     
  428.     
  429.         SetCursor(*GetCursor(watchCursor));
  430.     // Retrieve the page shape so we can add to it.
  431.         aPageShape = GetDocShape();
  432.         
  433.     // Create a line
  434.         aLineShape = GXNewLine (&aLineData);
  435.     
  436.         AddToShape(aPageShape, aLineShape);
  437.         GXDisposeShape(aLineShape);  
  438.     
  439.     
  440.     // Create a rectangle which is: red & is draw with it's frame.
  441.         aRectShape = GXNewRectangle(&aRectData); 
  442.          SetShapeCommonColor (aRectShape, red);
  443.         GXSetShapeFill (aRectShape, gxClosedFrameFill);
  444.         GXMoveShapeTo (aRectShape,  ff(150), ff(25));
  445.     
  446.         AddToShape(aPageShape, aRectShape);
  447.         GXDisposeShape(aRectShape);  
  448.     
  449.     // Create a curve which has: a 3.25 pen thickness
  450.         aCurveShape = GXNewCurve(&aCurveData); 
  451.         
  452.     // The fl marco converts floating gxPoint #'s to fixed gxPoint.
  453.         GXSetShapePen(aCurveShape, fl(3.25));
  454.         GXMoveShapeTo (aCurveShape,  ff(210), ff(25));
  455.     
  456.         AddToShape(aPageShape, aCurveShape);
  457.         GXDisposeShape(aCurveShape);  
  458.     
  459.     // Create apath which has: a 2 pen thickness, its color is green, and its drawn with its frame 
  460.         aPathShape = GXNewPaths((gxPaths *) a888Data);
  461.         GXSetShapeFill (aPathShape, gxClosedFrameFill);
  462.          GXSetShapePen(aPathShape, ff(2));
  463.         SetShapeCommonColor (aPathShape, green);
  464.     
  465.         GXMoveShapeTo (aPathShape,  ff(390), ff(25));
  466.     
  467.         AddToShape(aPageShape, aPathShape);
  468.         GXDisposeShape(aPathShape);  
  469.     
  470.     // Create a character S which is: colored in hsv space and it is rotated 15 degrees - six times
  471.     // via the left bottom corner.  Create the text, set the font size, and set the font name
  472.         aTextShape = GXNewText(1,(unsigned char*)"S",  nil);
  473.         SetShapeCommonFont(aTextShape, timesFont);
  474.         GXSetShapeTextSize(aTextShape, ff(200));
  475.         GXMoveShapeTo (aTextShape,  ff(25), ff(275));
  476.       GXSetShapeAttributes (aTextShape,  (GXGetShapeAttributes(aTextShape) | gxMapTransformShape));
  477.         
  478.     // Create an hsv color space and set up the initial colors
  479.         aTextColour.space = gxHSVSpace;
  480.         aTextColour.profile = nil;
  481.         aTextColour.element.hsv.hue = 0x7400;
  482.         aTextColour.element.hsv.saturation = 0xFFFF;
  483.         aTextColour.element.hsv.value = 0xFFFF;
  484.     
  485.     // Get the bounds of "aTextShape" and determine the bottom left corner
  486.         GXGetShapeBounds(aTextShape, 0L, &aTextBounds);
  487.         x = aTextBounds.left;
  488.         y = aTextBounds.bottom;
  489.     
  490.     // Rotate "aTextShape" 15 degrees - 6 times. Add each letter to the picture.
  491.         for (loop = 0; loop < 6; loop++) 
  492.         {
  493.             GXSetShapeColor(aTextShape, &aTextColour);
  494.             GXRotateShape(aTextShape, ff(15), x, y);
  495.             AddToShape(aPageShape, aTextShape);
  496.             aTextColour.element.hsv.hue += 0x0940;
  497.         }
  498.         GXDisposeShape(aTextShape); 
  499.                     
  500.     // Create a polygon which has the following features: yellow, drawn with a pen = 3, and
  501.     // skew it in the vertical direction by 0.5 
  502.         aPolygonShape = GXNewPolygons((gxPolygons *) aStarData);
  503.         GXSetShapeFill(aPolygonShape, gxEvenOddFill);
  504.         GXSetShapePen (aPolygonShape, ff(3));
  505.         SetShapeCommonColor (aPolygonShape, yellow);
  506.         GXMoveShapeTo (aPolygonShape,  ff(240), ff(110));
  507.         GXSkewShape(aPolygonShape, 0, fl(0.5), 0, 0);
  508.         
  509.         AddToShape(aPageShape, aPolygonShape);
  510.         GXDisposeShape(aPolygonShape); 
  511.         InitCursor();
  512.         fDocPageNum = fPagesInDoc = 1;
  513.     }
  514.     SetInspectShape(ePageShape, fPage);
  515.     SetInspectPage(fDocPageNum, fPagesInDoc);
  516.     this->SetDirty(true);
  517. #endif    // qUseQuickDrawGX
  518.  
  519. // Invalidate the window's portRect so that everything gets updated.
  520.     SetPort(fWindow);
  521.     InvalRect(&fWindow->portRect);
  522. }
  523.  
  524. void TGXDocWindow::GetContentRect(Rect* pRect)
  525. {
  526.     *pRect = fWindow->portRect;
  527.     pRect->top += kHeaderHeight;
  528.     pRect->bottom -= kScrollbarWidth;
  529.     pRect->right -=kScrollbarWidth;
  530. }
  531.  
  532. #if    qUseQuickDrawGX
  533. /*------ ResetContentClip ---------------------------------------------------------------------------*/
  534. //    This utility routine resets the clipping of the child view port that the page shape (contents) is in.
  535. void TGXDocWindow::ResetContentClip(void)
  536. {
  537.     Rect            aPortRect;
  538.     gxRectangle    aContentRect;
  539.     gxShape         aContentClipShape;
  540.     
  541.     // Inset the shape...
  542.     GetContentRect(&aPortRect);
  543.     aContentRect.top = ff(aPortRect.top);
  544.     aContentRect.bottom = ff(aPortRect.bottom);
  545.     aContentRect.right = ff(aPortRect.right);
  546.     aContentRect.left = ff(aPortRect.left);
  547.     aContentClipShape = GXNewRectangle(&aContentRect);
  548.         GXIgnoreGraphicsNotice(clip_already_set);        // <<••
  549.     GXSetViewPortClip(fContentViewPort, aContentClipShape);
  550.         GXPopGraphicsNotice();            // <<••
  551.     GXDisposeShape(aContentClipShape);
  552. }
  553. #endif    // qUseQuickDrawGX
  554.  
  555. void TGXDocWindow::AdjustForNewWindowSize(Rect* pOldSize,Rect* pNewSize)
  556. {
  557.     Rect    aScrollbarRect;
  558.  
  559.     //    Erase the new vertical scroll bar
  560.     if (pNewSize->right < pOldSize->right)
  561.         if ((pNewSize->right - pNewSize->left) > kScrollbarWidth)
  562.         {
  563.             aScrollbarRect = *pNewSize;
  564.             aScrollbarRect.top += kHeaderHeight;
  565.             aScrollbarRect.bottom -= kScrollbarWidth;
  566.             aScrollbarRect.left = aScrollbarRect.right - kScrollbarWidth;
  567.             EraseRect(&aScrollbarRect);
  568.         }
  569.     //    Erase the new horizontal scroll bar
  570.     if (pNewSize->bottom < pOldSize->bottom)
  571.         if ((pNewSize->bottom - pNewSize->top) > (kScrollbarWidth+kHeaderHeight))
  572.         {
  573.             aScrollbarRect = *pNewSize;
  574.             aScrollbarRect.top = aScrollbarRect.bottom - kScrollbarWidth;
  575.             aScrollbarRect.right -= kScrollbarWidth;
  576.             EraseRect(&aScrollbarRect);
  577.         }
  578.     TDocWindow::AdjustForNewWindowSize(pOldSize, pNewSize);
  579. #if    qUseQuickDrawGX
  580.     this->ResetContentClip();
  581. #endif    // qUseQuickDrawGX
  582. }
  583.  
  584. void TGXDocWindow::Draw(void)
  585. {
  586.     TDocWindow::Draw();
  587. #if    qUseQuickDrawGX
  588.     if (GetDocShape())
  589.     {
  590.         // Ref IM-DQ GX Objects pp 7-45,7-46
  591.         this->ResetContentClip();
  592.         GXDrawShape(GetDocShape());
  593.     }
  594. #endif    // qUseQuickDrawGX
  595. }
  596.  
  597. void  TGXDocWindow::HandleMenuCommand(short theMenuID, short theMenuItem)
  598. {
  599.     Boolean  aHandled = true;
  600.     switch(theMenuID)
  601.     {
  602.         case mEdit :
  603.             switch(theMenuItem)
  604.             {
  605.                 case    iNextPage:
  606.                     if (fDocPageNum < fPagesInDoc)
  607.                         ReadPage(fDocPageNum+1);
  608.                     break;
  609.                 case    iPreviousPage:
  610.                     if (fDocPageNum > 1)
  611.                         ReadPage(fDocPageNum-1);
  612.                     break;
  613.                 case    iGotoPage:
  614.                     break;
  615.                 default :        aHandled = false;                break;
  616.             }
  617.             break;
  618.             
  619.         default :        aHandled = false;                break;
  620.     }
  621.     if ( ! aHandled)
  622.         TDocWindow::HandleMenuCommand(theMenuID, theMenuItem);
  623. }
  624.  
  625. #define        RepaginateDoc()        
  626.  
  627. void TGXDocWindow::PageSetupDlg(Boolean theCustomFlag)
  628. {
  629. #if    qUseQuickDrawGX
  630.     gxDialogResult            aDialogResult;
  631.     gxEditMenuRecord        aEditMenuRecord;
  632.     
  633.     aEditMenuRecord.editMenuID    = mEdit;
  634.     aEditMenuRecord.cutItem        = iCut;
  635.     aEditMenuRecord.copyItem    = iCopy;
  636.     aEditMenuRecord.pasteItem    = iPaste;
  637.     aEditMenuRecord.clearItem    = iClear;
  638.     aEditMenuRecord.undoItem        = iUndo;
  639.  
  640.     EnableAllMenus(false);
  641.     if (theCustomFlag)
  642.     {
  643.         Boolean                aNewPageFormat = (fPageFormats[fDocPageNum-1] == nil);
  644.         gxFormat            aPageFormat;
  645.     // If we have an existing page format, we'll modify that.
  646.     // Otherwise, we'll need to create a new format and use that.
  647.         if (aNewPageFormat)
  648.         {
  649.             aPageFormat = GXNewFormat(fDocJob);
  650.             if(GXGetJobError(fDocJob))
  651.                 aPageFormat = nil;
  652.         }
  653.         else
  654.             aPageFormat = fPageFormats[fDocPageNum-1];
  655.         if (aPageFormat)
  656.         {
  657.             aDialogResult = GXFormatDialog(aPageFormat, &aEditMenuRecord, nil);
  658.             switch (aDialogResult)
  659.             {
  660.                 case gxRevertSelected:
  661.     //  If the user selected "Remove", use the default job format with this page. 
  662.     //  For our application, we indicate this by storing nil for the format reference in our structure.
  663.                     GXDisposeFormat(aPageFormat);
  664.                     fPageFormats[fDocPageNum-1] = nil;
  665.                     break;
  666.                 case gxOKSelected:
  667.                     fPageFormats[fDocPageNum-1] = aPageFormat;
  668.                     break;
  669.                 case gxCancelSelected:
  670.     // If the user selected "Cancel", dispose of our cloned copy
  671.     // of the default job format, if we made one.
  672.                     if (aNewPageFormat)
  673.                         GXDisposeFormat(aPageFormat);
  674.                     break;
  675.             }
  676.             if (aNewPageFormat)
  677.                 RepaginateDoc();
  678.         }
  679.     }
  680.     else
  681.     {
  682.         aDialogResult = GXJobDefaultFormatDialog(fDocJob, &aEditMenuRecord);
  683.         if (aDialogResult == gxOKSelected)
  684.             RepaginateDoc();
  685.     }
  686.         
  687.     EnableAllMenus(true);
  688.  
  689. #endif    // qUseQuickDrawGX
  690. }
  691.  
  692. #define        GXPrintLoop()
  693. void TGXDocWindow::PrintDlg(Boolean theDialogFlag)
  694. {
  695. #if    qUseQuickDrawGX
  696.     gxDialogResult            aDialogResult;
  697.     if (theDialogFlag)
  698.     {
  699.         gxEditMenuRecord        aEditMenuRecord;
  700.     
  701.         aEditMenuRecord.editMenuID    = mEdit;
  702.         aEditMenuRecord.cutItem        = iCut;
  703.         aEditMenuRecord.copyItem    = iCopy;
  704.         aEditMenuRecord.pasteItem    = iPaste;
  705.         aEditMenuRecord.clearItem    = iClear;
  706.         aEditMenuRecord.undoItem        = iUndo;
  707.     
  708.         EnableAllMenus(false);
  709.         aDialogResult = GXJobPrintDialog(fDocJob, &aEditMenuRecord);
  710.         EnableAllMenus(true);
  711.     }
  712.     else
  713.         aDialogResult = gxOKSelected;
  714.     if (aDialogResult == gxOKSelected)
  715.         GXPrintLoop();
  716. #endif    // qUseQuickDrawGX
  717. }
  718.  
  719. #if    qUseQuickDrawGX
  720. /*------ GetDocShape ---------------------------------------------------------------------------*/
  721. //    This utility routine returns the page shape (contents) attached to a window's document.
  722. gxShape TGXDocWindow::GetDocShape(void)
  723. {
  724.     return this->fPage;
  725. }
  726. #endif    // qUseQuickDrawGX
  727.  
  728. #if    qUseQuickDrawGX
  729. /*------ GetDocJob -----------------------------------------------------------------------------*/
  730. //    This utility routine returns the print job attached to a window's document.
  731. gxJob TGXDocWindow::GetDocJob(void)
  732. {
  733.     return this->fDocJob;
  734. }
  735. #endif    // qUseQuickDrawGX
  736.  
  737.  
  738.